package com.boot.mall.product.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.boot.common.to.seckill.SkuInfoTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.boot.mall.product.entity.SkuInfoEntity;
import com.boot.mall.product.service.SkuInfoService;
import com.boot.common.utils.PageUtils;
import com.boot.common.utils.R;



/**
 * sku信息
 *
 * @author huihui
 * @email 2565036109@qq.com
 * @date 2021-05-06 14:41:26
 */
@RestController
@RequestMapping("product/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 查询当前Sku的最新价格信息
     * @param skuId
     * @return
     */
    @GetMapping("/{skuId}/getCurrentPrice")
    public BigDecimal getSkuCurrentPrice(@PathVariable("skuId") Long skuId){
        BigDecimal newPrice = skuInfoService.getSkuCurrentPrice(skuId);
        return newPrice;
    }

    /**
     * 根据sku的ids查询sku的商品基本信息
     * @return
     */
    @GetMapping("/info/skIds")
    public Map<String, Object> getSkuInfoBySkuIds(@RequestParam List<String> ids){
        Map<String, Object> skuInfoTos = skuInfoService.getSkuInfoBySkuIds(ids);
        return skuInfoTos;
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils pageUtils = skuInfoService.pageSkuProductByCondition(params);
        return R.ok().put("page",pageUtils);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{skuId}")
    public R info(@PathVariable("skuId") Long skuId){
		SkuInfoEntity skuInfo = skuInfoService.getById(skuId);
        return R.ok().put("skuInfo", skuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] skuIds){
		skuInfoService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
